# $OpenBSD: Makefile,v 1.10 2017/05/31 08:10:01 espie Exp $

COMMENT =	Enhanced Duke Nukem 3D engine
RDATE =		20160610
RTAG =		5775
DISTNAME =	eduke32_src_${RDATE}-${RTAG}
PKGNAME =	eduke32-2.0.0.${RTAG}
EXTRACT_SUFX =	.tar.xz
CATEGORIES =	games x11
REVISION =	0

HOMEPAGE =	http://www.eduke32.com/

MAINTAINER =	Ryan Freeman <ryan@slipgate.org>

# GPLv2, BUILD license and shareware data
PERMIT_PACKAGE_CDROM =  "BUILD engine license is not compatible with GPLv2."
PERMIT_PACKAGE_FTP =    "BUILD engine license is not compatible with GPLv2."
PERMIT_DISTFILES_FTP =  "BUILD engine license is not compatible with GPLv2."

BUILD_DEPENDS = archivers/unzip \
		graphics/gdk-pixbuf2

.if ${MACHINE_ARCH} == "i386"
BUILD_DEPENDS += devel/nasm
.endif

WANTLIB += c m ogg png pthread vorbis vorbisfile vpx z lz4
WANTLIB += SDL2 SDL2_mixer FLAC execinfo ${LIBECXX}

LIB_DEPENDS =	archivers/lz4 \
		audio/libvorbis \
		audio/flac \
		devel/sdl2 \
		devel/sdl2-mixer \
		devel/libexecinfo \
		multimedia/libvpx

# dlopen()'d; shows as Extra in check-lib-depends but it is used
LIB_DEPENDS +=	x11/gtk+2
WANTLIB +=	gtk-x11-2.0

RUN_DEPENDS =	games/duke3ddata

MASTER_SITES =	http://dukeworld.duke4.net/eduke32/synthesis/${RDATE}-${RTAG}/

COMPILER =	gcc

# make sure we can see compilation output, respect CC/CXX, don't strip!
MAKE_ENV =	PRETTY_OUTPUT=0 \
		PACKAGE_REPOSITORY=1
MAKE_FLAGS +=	CC="${CC}" \
		CXX="${CXX}" \
		STRIP=true
USE_GMAKE =	Yes
NO_TEST =	Yes

WRKDIST =	${WRKDIR}/eduke32_${RDATE}-${RTAG}

post-extract:
	# check for data files in correct location
	@sed -i "s,/usr/share/games/eduke32,${TRUEPREFIX}/share/duke3d," \
		${WRKSRC}/source/common.c
	rm ${WRKSRC}/build/include/lz4.h ${WRKSRC}/build/src/lz4.c

do-install:
	${INSTALL_PROGRAM} ${WRKBUILD}/eduke32 ${PREFIX}/bin
	${INSTALL_PROGRAM} ${WRKBUILD}/mapster32 ${PREFIX}/bin
	${INSTALL_DATA_DIR} ${PREFIX}/share/duke3d
	${INSTALL_DATA_DIR} ${PREFIX}/share/doc/eduke32
	${INSTALL_DATA_DIR} ${PREFIX}/share/examples/eduke32
	# mapster32 help files
	${INSTALL_DATA} ${WRKDIST}/package/sdk/m32help.hlp \
		${PREFIX}/share/duke3d/
	${INSTALL_DATA} ${WRKDIST}/package/sdk/SEHELP.HLP \
		${PREFIX}/share/duke3d/
	${INSTALL_DATA} ${WRKDIST}/package/sdk/STHELP.HLP \
		${PREFIX}/share/duke3d/
	# mapster32 config and config header file
	${INSTALL_DATA} ${WRKDIST}/package/sdk/tiles.cfg \
		${PREFIX}/share/duke3d/
	${INSTALL_DATA} ${WRKDIST}/package/sdk/names.h \
		${PREFIX}/share/duke3d/
	# eduke32/mapster32 licenses
	${INSTALL_DATA} ${WRKDIST}/package/common/gpl-2.0.txt \
		 ${PREFIX}/share/doc/eduke32/
	${INSTALL_DATA} ${WRKDIST}/package/common/buildlic.txt \
		${PREFIX}/share/doc/eduke32/
	# sample game mapping/modding data files
	${INSTALL_DATA} ${WRKDIST}/package/sdk/samples/* \
		${PREFIX}/share/examples/eduke32/

.if ${MACHINE_ARCH:Mi386}
CFLAGS +=	-fno-pie
MAKE_FLAGS +=	MISCLINKOPTS=-nopie
.endif

.include <bsd.port.mk>
.if ${PROPERTIES:Mclang}
# lto doesn't work with binutils, at all
MAKE_FLAGS +=	LDFLAGS=-fuse-ld=/usr/bin/ld.lld
# alternately, we could disable LTO
# MAKE_FLAGS +=	LTO=0
.endif
